$(function() {

    let searchObj = {
        key: '',
        type: '',
        page: '',
        perpage: ''
    }


    function getSearch() {
        $.ajax({
            type: 'get',
            url: '/index/search',
            data: searchObj,
            success: (backData) => {
                console.log(backData)
            },
        })
    }
    getSearch();

    $('.search_btn').on('click', function() {
        let keyText = $('.search_txt').val().trim();
        searchObj.key = keyText;
        console.log(searchObj.key);
        window.location.href = './list.html?key=' + searchObj.key
    })



    $.ajax({
        type: 'get',
        url: '/index/category',
        //   data: {},
        success: (backData) => {
            // console.log(backData);
            let categoryRes = template('categoryTemp', backData);
            let categoryMenuRes = template('categoryMenuTemp', backData)
            $('ul.level_two').html(categoryRes)
            $('ul.left_menu').html(categoryMenuRes)
        },
    });

    $.ajax({
        type: 'get',
        url: '/index/hotpic',
        data: {},
        success: (backData) => {
            // console.log(backData);
            let focusRes = template('focusTemp', backData);
            // console.log(focusRes);
            $('ul.focus_list').html(focusRes)
        },
    })

    $.ajax({
        type: 'get',
        url: '/index/rank',
        data: {},
        success: (backData) => {
            // console.log(backData)
            let rankingRes = template('rankingTemp', backData);
            $('.hotrank_list').html(rankingRes)
        },
    })

    $.ajax({
        type: 'get',
        url: '/index/latest_comment',
        data: {},
        success: (backData) => {
            // console.log(backData)
            let commentRes = template('commentTemp', backData);
            $('.comment_list').html(commentRes)
        },
    })

    $.ajax({
        type: 'get',
        url: '/index/latest',
        data: {},
        success: (backData) => {
            // console.log(backData)
            let newsRes = template('newsTemp', backData);
            $('div.common_news').html(newsRes)
        },
    })

    $.ajax({
        type: 'get',
        url: '/index/attention',
        data: {},
        success: (backData) => {
            // console.log(backData)
            let attentionRes = template('attentionTemp', backData);
            $('.guanzhu_list').html(attentionRes)
        },
    })
})